<template>
    <div class="wrap-table fllow-manage conItem">
        <el-form ref="form" :model="searchData" label-width="100px" class="clearfix flex-div">
            <el-form-item label="就诊日期" class="" label-width="70px" style="width:350px">
                <div class="block">
                    <el-date-picker
                            v-model="timeDate"
                            type="daterange"
                            align="right"
                            unlink-panels
                            range-separator="至"
                            value-format="yyyy-MM-dd"
                            start-placeholder="开始日期"
                            end-placeholder="结束日期"
                            :picker-options="pickerOptions">
                    </el-date-picker>
                </div>
            </el-form-item>
            <el-form-item label="预约状态" class="" style="width: 200px">
                <el-select v-model="searchData.appointState" clearable placeholder="请选择">
                    <el-option
                            v-for="item in options1"
                            :key="item.value"
                            :label="item.label"
                            :value="item.value">
                    </el-option>
                </el-select>
            </el-form-item>
            <el-form-item label="所在地区" class=" item-right" style="width:220px">
                <el-select v-model="searchData.districtNo" placeholder="请选择"  clearable :disabled="JSON.parse(UserDic).IsCommunityOnly=='1'">
                    <el-option
                            v-for="item in optionDiq"
                            :key="item.DistrictName"
                            :label="item.DistrictName"
                            :value="item.DistrictNo">
                    </el-option>
                </el-select>
            </el-form-item>
            <!--<transition name="fade">-->
                <!--<div class="moreSearch" v-show="showActive">-->
                    <el-form-item label="事项状态" class=""  style="width: 200px">
                        <el-select v-model="searchData.completeState" clearable placeholder="请选择">
                            <el-option
                                    v-for="item in options2"
                                    :key="item.value"
                                    :label="item.label"
                                    :value="item.value">
                            </el-option>
                        </el-select>
                    </el-form-item>
                    <el-form-item label="门诊时研究阶段" label-width="130px" class="" style="width:220px">
                        <el-select v-model="searchData.period" clearable placeholder="请选择">
                            <el-option
                                    v-for="item in options2sp"
                                    :key="item.value"
                                    :label="item.label"
                                    :value="item.value">
                            </el-option>
                        </el-select>
                    </el-form-item>
                    <el-form-item label="试验类型" class=" item-right" style="width:260px">
                        <el-select v-model="searchData.testType" clearable placeholder="请选择">
                            <el-option
                                    v-for="item in options6"
                                    :key="item.value"
                                    :label="item.label"
                                    :value="item.value">
                            </el-option>
                        </el-select>
                    </el-form-item>

                    <el-form-item class=" item-right" style="width:300px;margin-left: -60px" label="">
                        <el-input v-model="searchData.keyWord" placeholder="研究对象手机号"></el-input>
                    </el-form-item>
                <!--</div>-->
            <!--</transition>-->
            <div class="flex-r-but">
                <el-button type="primary" @click="checkList" class=" mg-lr-20 pd-bt">查询</el-button>
            </div>

            <!--<el-button class="pull-right" @click="showActive=!showActive"><span v-if="!showActive">更多</span><span v-else>收起</span></el-button>-->
        </el-form>
        <!---->
        <template>
            <el-table
                    :data="tableData"
                    border
                    v-loading="loading"
                    element-loading-text="加载中"
                    style="width: 100%">
                <el-table-column align="center" label="序号" width="70">
                    <template  slot-scope="scope">
                        {{scope.$index+1}}
                    </template>
                </el-table-column>
                <el-table-column
                        prop="VisitDate"
                        align="center"
                        label="就诊日期"
                        min-width="160">
                    <template  slot-scope="scope">
                        <el-date-picker
                                v-model="scope.row.VisitDate"
                                 :disabled="true"
                                :clearable="false"
                                @change="changeFollowUpDate(scope.row,scope.row.VisitDate)"
                                type="date"
                                value-format="yyyy-MM-dd"
                                placeholder="选择日期">
                        </el-date-picker>
                    </template>
                </el-table-column>
                <el-table-column
                        prop="VisitTime"
                        label="预约时间"
                        align="center"
                        min-width="120">
                    <template  slot-scope="scope">
                        <el-time-select
                                v-model="scope.row.VisitTime"
                                :clearable="false"
                                @change="changeFollowUpDateOne(scope.row,scope.row.VisitTime)"
                                :picker-options="{start: '08:00', step: '00:15',end: '21:30'}"
                                placeholder="">
                        </el-time-select>
                    </template>
                </el-table-column>
                <el-table-column
                        prop="AppointState"
                        label="预约状态"
                        align="center"
                        :formatter="AppointFilter"
                        min-width="120">
                    <template  slot-scope="scope">
                        <el-select v-model="scope.row.AppointState" placeholder="请选择" @change="changeFollowUpDate(scope.row,scope.row.AppointState)">
                            <el-option
                                    v-for="item in options1s"
                                    :key="item.value"
                                    :label="item.label"
                                    :value="item.value">
                            </el-option>
                        </el-select>
                    </template>
                </el-table-column>
                <el-table-column
                        prop="CompleteState"
                        label="事项状态"
                        :formatter="FollowUpFilter"
                        align="center"
                        min-width="120">
                    <template  slot-scope="scope">
                        <el-select v-model="scope.row.CompleteState" placeholder="请选择" @change="changeFollowUpDate(scope.row,scope.row.CompleteState)">
                            <el-option
                                    v-for="item in options3s"
                                    :key="item.value"
                                    :label="item.label"
                                    :value="item.value">
                            </el-option>
                        </el-select>
                    </template>
                </el-table-column>
                <el-table-column
                        prop="Nurse"
                        label="营养师"
                        align="center"
                        min-width="120">
                    <template slot-scope="scope">
                        <el-select v-model="scope.row.Nurse" placeholder="请选择" @change="changeNurse(scope.row,scope.row.Nurse)">
                            <el-option
                                v-for="item in optionsNurse"
                                :key="item.SYS_ID"
                                :label="item.icons"
                                :value="item.icons">
                            </el-option>
                        </el-select>
                    </template>
                </el-table-column>
                <el-table-column
                        prop="Surname"
                        label="姓名首字母"
                        align="center"
                        min-width="100">
                </el-table-column>
                 <el-table-column
                    prop="ResearchNo"
                    label="研究编号"
                    align="center"
                    min-width="120"
                    ></el-table-column>
                <el-table-column
                        label="手机号"
                        align="center"
                        min-width="100">
                    <template slot-scope="scope">
                        <el-tooltip :content="scope.row.Mobile" placement="top">
                            <span class="click_line" @click="JumpUserinfo(scope.row)">{{scope.row.Mobile |mobileFilter}}</span>
                        </el-tooltip>
                    </template>
                </el-table-column>
                <el-table-column
                        prop="Period"
                        label="门诊时研究阶段"
                        :formatter="PeriodFilter"
                        align="center"
                        min-width="120">
                </el-table-column>
                <!--<el-table-column-->
                        <!--prop="IntensityOfIntervention"-->
                        <!--label="干预强度"-->
                        <!--:formatter="IntensityFilter"-->
                        <!--align="center"-->
                        <!--min-width="100">-->
                <!--</el-table-column>-->
                <el-table-column
                        prop="Remark"
                        label="事项备注"
                        align="center"
                        min-width="160">
                    <template slot-scope="scope">
                        <el-input @blur="changeFollowUpDate(scope.row,scope.row.FollowUpState)" v-model="scope.row.Remark" placeholder="事项备注"></el-input>
                    </template>
                </el-table-column>
                <el-table-column
                        prop="CancleReason"
                        label="事项取消原因"
                        align="center"
                        min-width="160">
                    <template slot-scope="scope">
                        <el-input @blur="changeFollowUpDate(scope.row,scope.row.FollowUpState)" v-model="scope.row.CancleReason" placeholder="事项取消原因"></el-input>
                    </template>
                </el-table-column>
                <el-table-column
                        fixed="right"
                        min-width="100"
                        align="center"
                        label="营养处方">
                    <template  slot-scope="scope">
                        <el-button size="small" style="color: #f00" v-if="scope.row.NutritionPrescriptionId==''" type="text" label="去生成"
                                   @click="handleTable(scope.row)">去生成</el-button>
                        <span  class="click_line"  v-else @click="jumpMove(scope.row)"><span
                                v-if="scope.row.IsDraftNutritionPrescription==0" style="color: #f00">去修改</span><span v-else>已生成</span></span>
                    </template>
                </el-table-column>
                <el-table-column
                        fixed="right"
                        min-width="140"
                        align="center"
                        label="营养咨询CRF">
                    <template  slot-scope="scope">
                        <el-button v-if="scope.row.NurtritionCaseReportId!==''" size="small" type="text"  @click="handleReport(scope.row)">查看</el-button>
                        <el-button style="color: #f00" v-else size="small" type="text"  @click="handleReport(scope.row)">填写</el-button>
                    </template>
                </el-table-column>
            </el-table>
        </template>
        <!--分页-->
        <div class="block mg-20-auto pagination-fixed">
            <el-pagination
                    @size-change="handleSizeChange"
                    @current-change="handleCurrentChange"
                    :current-page.sync="pageId"
                    :page-sizes="[10, 20, 30, 40]"
                    :page-size="pageSize"
                    layout="total, sizes, prev, pager, next, jumper"
                    :total="total">
            </el-pagination>
        </div>
        <!--案例报告表  oneStep-->
        <el-dialog title="营养咨询CRF" :visible.sync="dialogFormAnli" :append-to-body="true" top="0" width="60%"
                   :close-on-click-modal="false">
                <div style="margin-right: 20px;overflow-x: hidden">
                    <p style="margin-bottom: 15px;font-weight: bold">研究对象：{{formPoint.Surname}}({{formPoint.ResearchNo}}) <span
                            style="padding-left: 15px;">研究阶段：{{formPoint.Period |PeriodFilters}}</span>
                        <span style="padding-left: 15px;">手机号：{{formPoint.Mobile |mobileFilter}}</span>
                    </p>
                    <el-form :model="FormAnli" :rules="rules1" label-position="left" ref="FormAnli" label-width="60%" class="demo-ruleForm">
                        <el-form-item label="预约日期" prop="VistDate">
                            <el-date-picker
                                    v-model="FormAnli.VistDate"
                                    type="date"
                                    value-format="yyyy-MM-dd"
                                    placeholder="选择日期">
                            </el-date-picker>
                        </el-form-item>
                        <el-form-item label="开始时间" prop="StartTime">
                            <el-time-picker
                                    v-model="FormAnli.StartTime"
                                    range-separator="-"
                                    value-format="HH:mm"
                                    format="HH:mm"
                                    placeholder="请选择">
                            </el-time-picker>
                        </el-form-item>
                        <el-form-item label="结束时间" prop="EndTime">
                            <el-time-picker
                                    v-model="FormAnli.EndTime"
                                    range-separator="-"
                                    format="HH:mm"
                                    value-format="HH:mm"
                                    placeholder="请选择">
                            </el-time-picker>
                        </el-form-item>
                        <el-form-item label="门诊类型" prop="OutpatientType">
                            <el-select v-model="FormAnli.OutpatientType" placeholder="请选择" clearable>
                                <div v-if="formPoint.Period == '1'">
                                    <el-option label="孕前期第一次(强制性)" value="1"></el-option>
                                    <el-option label="孕前期第二次(选择性)" value="2"></el-option>
                                </div>
                                <div v-else>
                                    <el-option label="怀孕期第一次(强制性)" value="3"></el-option>
                                    <el-option label="怀孕期第二次(选择性)" value="4"></el-option>
                                    <el-option label="怀孕期第三次(强制性)" value="5"></el-option>
                                    <el-option label="怀孕期第四次(选择性)" value="6"></el-option>
                                </div>
                            </el-select>
                        </el-form-item>
                        <el-form-item label="随访类型" prop="VisitType">
                            <el-select v-model="FormAnli.VisitType" placeholder="请选择" clearable>
                                <el-option label="营养咨询#1" value="1"></el-option>
                                <el-option label="随访" value="4"></el-option>
                                <el-option label="营养咨询#2" value="2"></el-option>
                                <el-option label="营养咨询#3" value="3"></el-option>
                            </el-select>
                        </el-form-item>
                        <p class="formPlebek">营养咨询前</p>
                        <el-form-item label="预览过研究对象的相关材料 (之前的营养报告，行动计划, 体重追踪记录, 健康现况表)?" prop="IsViewPriorData">
                            <el-select v-model="FormAnli.IsViewPriorData" placeholder="请选择" clearable>
                                <el-option label="是" value="1"></el-option>
                                <el-option label="否" value="2"></el-option>
                            </el-select>
                        </el-form-item>
                        <el-form-item label="与干预护士交流过研究对象的情况?" prop="IsChatWithNurse">
                            <el-select v-model="FormAnli.IsChatWithNurse" placeholder="请选择" clearable>
                                <el-option label="是" value="1"></el-option>
                                <el-option label="否" value="2"></el-option>
                            </el-select>
                        </el-form-item>
                        <p class="formPlebek">营养咨询中</p>
                        <el-form-item label="谁陪研究对象一起来做营养咨询的？请勾选" prop="Companions">
                            <el-checkbox-group v-model="Companions" @change="changeCops">
                                <el-checkbox label="研究对象自己"></el-checkbox>
                                <el-checkbox label="丈夫/伴侣"></el-checkbox>
                                <el-checkbox label="母亲"></el-checkbox>
                                <el-checkbox label="婆婆"></el-checkbox>
                                <el-checkbox label="父亲"></el-checkbox>
                                <el-checkbox label="公公"></el-checkbox>
                                <el-checkbox label="其他"></el-checkbox>
                            </el-checkbox-group>
                            <el-input v-if="Companions.indexOf('其他')>-1" v-model="FormAnli.CompanionsOther"  placeholder="请输入内容"></el-input>
                        </el-form-item>
                        <el-form-item label="研究对象在就诊前已完成《3天饮食日记》 (3DD)?" prop="IsComplete3DD">
                            <el-select v-model="FormAnli.IsComplete3DD" placeholder="请选择" clearable>
                                <el-option label="是" value="1"></el-option>
                                <el-option label="否" value="2"></el-option>
                            </el-select>
                        </el-form-item>
                        <el-form-item label="没有完成3DD" prop="UnComplete3DDReason" v-if="FormAnli.IsComplete3DD=='2'">
                            <el-radio-group v-model="FormAnli.UnComplete3DDReason">
                                <el-radio label="忘记了">忘记了</el-radio>
                                <el-radio label="没有时间">没有时间</el-radio>
                                <el-radio label="太难了">太难了</el-radio>
                                <el-radio label="其他">其他</el-radio>
                            </el-radio-group>
                            <el-input v-if="FormAnli.UnComplete3DDReason=='其他'" v-model="FormAnli.UnComplete3DDReasonOther"  placeholder="请输入内容"></el-input>
                        </el-form-item>

                        <el-form-item label="与研究对象一起审阅和确认3DD的内容?" prop="IsTogetherView3DD">
                            <el-select v-model="FormAnli.IsTogetherView3DD" placeholder="请选择" clearable>
                                <el-option label="是" value="1"></el-option>
                                <el-option label="否" value="2"></el-option>
                            </el-select>
                        </el-form-item>

                        <el-form-item label="使用臻鼎“营养之星”录入了3DD?" prop="IsFillIn3DD">
                            <el-select v-model="FormAnli.IsFillIn3DD" placeholder="请选择" clearable>
                                <el-option label="是" value="1"></el-option>
                                <el-option label="否" value="2"></el-option>
                            </el-select>
                        </el-form-item>
                        <el-form-item label="有没有做《24小时膳食回顾》?" prop="IsReviewDiet">
                            <el-select v-model="FormAnli.IsReviewDiet" placeholder="请选择" clearable>
                                <el-option label="是" value="1"></el-option>
                                <el-option label="否" value="2"></el-option>
                            </el-select>
                        </el-form-item>
                        <el-form-item label="使用臻鼎“营养之星”录入了《24小时膳食回顾》？" prop="IsFillInDiet">
                            <el-select v-model="FormAnli.IsFillInDiet" placeholder="请选择" clearable>
                                <el-option label="是" value="1"></el-option>
                                <el-option label="否" value="2"></el-option>
                            </el-select>
                        </el-form-item>
                        <el-form-item label="《膳食评估报告》已生成并保存?" prop="IsSaveDietReport">
                            <el-select v-model="FormAnli.IsSaveDietReport" placeholder="请选择" clearable>
                                <el-option label="是" value="1"></el-option>
                                <el-option label="否" value="2"></el-option>
                            </el-select>
                        </el-form-item>
                        <el-form-item label="与研究对象一起审阅和确认《膳食评估报告》的内容?" prop="IsTogetherConfirmDietReport">
                            <el-select v-model="FormAnli.IsTogetherConfirmDietReport" placeholder="请选择" clearable>
                                <el-option label="是" value="1"></el-option>
                                <el-option label="否" value="2"></el-option>
                            </el-select>
                        </el-form-item>
                        <el-form-item label="《营养处方表》已完成" prop="IsCompleteNurtitionPrescription">
                            <el-select v-model="FormAnli.IsCompleteNurtitionPrescription" placeholder="请选择" clearable>
                                <el-option label="是" value="1"></el-option>
                                <el-option label="否" value="2"></el-option>
                            </el-select>
                        </el-form-item>
                        <el-form-item label="安排下一次营养咨询的时间?" prop="IsSetNextVisitDate">
                            <el-select v-model="FormAnli.IsSetNextVisitDate" placeholder="请选择" clearable>
                                <el-option label="是" value="1"></el-option>
                                <el-option label="否" value="2"></el-option>
                                <el-option label="N/A" value="3"></el-option>
                            </el-select>
                        </el-form-item>
                        <p class="formPlebek">营养咨询结束后</p>
                        <el-form-item label="与干预护士交流了该研究对象的情况?" prop="IsCommunicationWithNurse">
                            <el-select v-model="FormAnli.IsCommunicationWithNurse" placeholder="请选择" clearable>
                                <el-option label="是" value="1"></el-option>
                                <el-option label="否" value="2"></el-option>
                            </el-select>
                        </el-form-item>
                        <p style="margin:10px 0px;">其他意见</p>
                        <el-input
                                type="textarea"
                                :rows="3"
                                placeholder=""
                                v-model="FormAnli.OtherOpinion">
                        </el-input>
                    </el-form>
                </div>
            <div slot="footer" class="dialog-footer">
                <el-button v-if="RoleGroup==1 &&hasCount" @click="deleteCrf" style="float: left;">删除</el-button>
                <el-button @click="dialogFormAnli = false">取 消</el-button>
                <el-button type="primary" @click="reportSure('FormAnli')">保存</el-button>
            </div>
        </el-dialog>
        <!--查看-->
        <el-dialog title="营养处方" :visible.sync="dialogForm1" :append-to-body="true" top="0" width="60%"
                   :close-on-click-modal="false">
                <div style="margin-right: 20px">
                    <p style="margin-bottom: 15px;font-weight: bold">研究对象：{{formPoint.Surname}}({{formPoint.ResearchNo}}) <span
                            style="padding-left: 15px;">研究阶段：{{formPoint.Period |PeriodFilters}}</span>
                        <span style="padding-left: 15px;">手机号：{{formPoint.Mobile |mobileFilter}}</span>
                    </p>
                    <div class="formX">
                        <span style="color: #2DA3FB;margin-bottom: 5px;display: inline-block;cursor: pointer" @click="copyMove">复制以往营养处方</span>
                        <ul>
                            <li>
                                <h3>1.能量和宏量营养素（蛋白质，脂类，碳水化合物）摄入是否充足，比例是否适宜?</h3>
                                <el-select v-model="formx.Energy" placeholder="请选择" style="width: 200px;margin:18px 0px 5px 0px;">
                                    <el-option label="是" value="1"></el-option>
                                    <el-option label="否" value="2"></el-option>
                                </el-select>
                                <p>详情:</p>
                                <el-input
                                        type="textarea"
                                        :rows="3"
                                        :disabled="Plis"
                                        placeholder=""
                                        v-model="formx.EnergyDetail">
                                </el-input>
                            </li>
                            <li>
                                <h3>2.各类食物摄入的种类和数量是否适宜?</h3>
                                <el-select v-model="formx.FoodCount" placeholder="请选择" style="width: 200px;margin:18px 0px 5px 0px;">
                                    <el-option label="是" value="1"></el-option>
                                    <el-option label="否" value="2"></el-option>
                                </el-select>
                                <p>详情:</p>
                                <el-input
                                        type="textarea"
                                        :rows="3"
                                        :disabled="Plis"
                                        placeholder=""
                                        v-model="formx.FoodCountDetail">
                                </el-input>
                            </li>
                            <li>
                                <h3>3.主要微量营养素摄入是否充足，比例是否适宜? (钙，铁，碘，维生素A,叶酸)</h3>
                                <el-select v-model="formx.TraceElement" placeholder="请选择" style="width: 200px;margin:18px 0px 5px 0px;">
                                    <el-option label="是" value="1"></el-option>
                                    <el-option label="否" value="2"></el-option>
                                </el-select>
                                <p>详情:</p>
                                <el-input
                                        type="textarea"
                                        :rows="3"
                                        :disabled="Plis"
                                        placeholder=""
                                        v-model="formx.TraceElementDetail">
                                </el-input>
                            </li>
                            <li>
                                <h3>4.饮食上存在的主要问题、误区?</h3>
                                <p>问题1:</p>
                                <el-input
                                        type="textarea"
                                        :rows="3"
                                        :disabled="Plis"
                                        placeholder=""
                                        v-model="formx.DietQuestion1">
                                </el-input>
                                <p>问题2(可选):</p>
                                <el-input
                                        type="textarea"
                                        :rows="3"
                                        :disabled="Plis"
                                        placeholder=""
                                        v-model="formx.DietQuestion2">
                                </el-input>
                                <p>问题3(可选):</p>
                                <el-input
                                        type="textarea"
                                        :rows="3"
                                        :disabled="Plis"
                                        placeholder=""
                                        v-model="formx.DietQuestion3">
                                </el-input>
                            </li>
                            <li>
                                <h3>5.建议</h3>
                                <p>建议1:</p>
                                <el-input
                                        type="textarea"
                                        :rows="3"
                                        :disabled="Plis"
                                        placeholder=""
                                        v-model="formx.Advice1">
                                </el-input>
                                <p>建议2(可选):</p>
                                <el-input
                                        type="textarea"
                                        :rows="3"
                                        :disabled="Plis"
                                        placeholder=""
                                        v-model="formx.Advice2">
                                </el-input>
                                <p>建议3(可选):</p>
                                <el-input
                                        type="textarea"
                                        :rows="3"
                                        :disabled="Plis"
                                        placeholder=""
                                        v-model="formx.Advice3">
                                </el-input>
                            </li>
                            <li>
                                <h3>6.营养师提供的资源</h3>
                                <el-checkbox-group v-model="labelList" style="margin:18px 0px;" @change="changeLabellist">
                                    <el-checkbox label="中国居民平衡膳食餐盘"></el-checkbox>
                                    <el-checkbox label="膳食宝塔"></el-checkbox>
                                    <el-checkbox label="食谱"></el-checkbox>
                                    <el-checkbox label="其他" ></el-checkbox>
                                    <el-checkbox label="无"></el-checkbox>
                                </el-checkbox-group>
                                <p>详情:</p>
                                <el-input
                                        type="textarea"
                                        :rows="3"
                                        :disabled="Plis"
                                        placeholder=""
                                        v-model="formx.NurtritionResourcesDetail">
                                </el-input>
                            </li>
                        </ul>
                        </el-form>
                    </div>
                </div>
            <div slot="footer" class="dialog-footer" v-if="formx.IsDraft==0">
                <el-button @click="dialogForm1 = false">取 消</el-button>
                <el-button @click="submitForm(0)">保存草稿</el-button>
                <el-button type="primary" @click="submitForm(1)">提交</el-button>
            </div>
        </el-dialog>
        <el-dialog title="复制既往营养处方" :visible.sync="dialogForm2" :append-to-body="true" top="0" width="60%"
                   :close-on-click-modal="false">
            <!-- -->
            <template>
                <el-table
                        :data="tableDataQ"
                        border
                        ref="singleTable"
                        @selection-change="singleChange"
                        element-loading-text="加载中"
                        style="width: 100%;">
                    <el-table-column
                            type="selection"
                            width="55">
                    </el-table-column>
                    <el-table-column
                            prop="CreateTime"
                            label="创建时间"
                            :show-overflow-tooltip="true"
                            align="center"
                            min-width="60">
                    </el-table-column>
                    <el-table-column
                            prop="Creater"
                            label="创建人"
                            align="center"
                            min-width="60">
                    </el-table-column>
                </el-table>
            </template>
            <!--分页-->
            <div class="block mg-20-auto" style="padding:10px 0px 20px 0px;">
                
                <el-button style="float: right" type="primary" @click="makeSurecopy">确认复制</el-button>
            </div>

        </el-dialog>
    </div>
</template>
<script>
import {mapGetters} from 'vuex'
import {DIC_PERIODA,filterPeriod} from '@/utils/localDic'
export default {
    data() {
        return {
            searchData:{
                // sysId:'',
                appointState:'',
                completeState: '',
                userState:'',
                groupType:'',
                keyWord:'',
                period:'',
                districtNo:'',
                testType:'2'
            },
            timeDate:[],
            pickerOptions: {
                shortcuts: [{
                    text: '最近一周',
                    onClick(picker) {
                    const end = new Date();
                    const start = new Date();
                    start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
                    picker.$emit('pick', [start, end]);
                    }
                }, {
                    text: '最近一个月',
                            onClick(picker) {
                        const end = new Date();
                        const start = new Date();
                        start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
                        picker.$emit('pick', [start, end]);
                    }
                }, {
                    text: '最近三个月',
                            onClick(picker) {
                        const end = new Date();
                        const start = new Date();
                        start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
                        picker.$emit('pick', [start, end]);
                    }
                }],
            },
            pageId:1,
            total:null,
            loading:true,
            pageSize:10,
            tableData:[],
            options1:  [{value: '', label: '全部'},{value: '0', label: '待确认'},{value: '1', label: '已确认'}, {value: '2', label: '已取消'}],
            options1s: [{value: '0', label: '待确认'},{value: '1', label: '已确认'}, {value: '2', label: '已取消'}],
            options2: [{value: '', label: '全部'},{value: '0', label: '待完成'}, {value: '1', label: '已完成'}, {value: '2', label: '已取消'}, {value: '3', label: '爽约'}],
            options3s: [ {value: '0', label: '待完成'}, {value: '1', label: '已完成'},{value: '2', label: '已取消'}, {value: '3', label: '爽约'}],
            optionss6: [{value: '', label: '全部'},{value: '1', label: 'A'}, {value: '2', label: 'B'}],
            options6: [{value: '', label: '全部'},{value: '0', label: '预试验'},{value: '1', label: '正式试验'},{value: '2', label: '预试验+正式试验'}],
            options2sp:DIC_PERIODA,
            PeriodFilter(row, column, cellValue, index){
                return filterPeriod(cellValue)
            },
            IntensityFilter(row, column, cellValue, index){
                return cellValue==1?'AA':'A'
            },
            AppointFilter(row, column, cellValue, index){
                return cellValue==1?'已预约':(cellValue==0?'待确认':'已取消')
            },
            FollowUpFilter(row, column, cellValue, index){
                return cellValue==1?'已完成':'待完成'
            },
            maxHeight:'',
            ResearchObjectId:'',
            ScheduleId:'',
            showActive:false,
            pageSizeQ:5,
            pageIdQ:1,
            tablerow:null,
            totalQ:null,
            copyObject:null,
            onOFFsub:false,
            optionsNurse:[],
            dialogVisible:false,
            dialogFormAnli:false,
            formPoint:{},
            FormAnli:{
                IsCommunicationWithNurse:'',
                IsSetNextVisitDate:'',
                IsCompleteNurtitionPrescription:'',
                IsTogetherConfirmDietReport:'',
                IsSaveDietReport:'',
                IsFillInDiet:'',
                IsReviewDiet:'',
                IsFillIn3DD:'',
                IsTogetherView3DD:'',
                UnComplete3DDReason:'',
                IsComplete3DD:'',
                CompanionsOther:'',
                Companions:'',
                IsChatWithNurse:'',
                IsViewPriorData:'',
                VisitType:'',
                EndTime:'',
                StartTime:'',
                VistDate:'',
                OtherOpinion:'',
	            OutpatientType:''
            },
            rules1:{
                IsCommunicationWithNurse:[
                    { required: true,message: '必填项',trigger: 'change'}
                ],
                        IsSetNextVisitDate:[
                    { required: true,message: '必填项',trigger: 'change'}
                ],
                        IsCompleteNurtitionPrescription:[
                    { required: true,message: '必填项',trigger: 'change'}
                ],
                        IsTogetherConfirmDietReport:[
                    { required: true,message: '必填项',trigger: 'change'}
                ],
                        IsSaveDietReport:[
                    { required: true,message: '必填项',trigger: 'change'}
                ],
                        IsFillInDiet:[
                    { required: true,message: '必填项',trigger: 'change'}
                ],
                        IsReviewDiet:[
                    { required: true,message: '必填项',trigger: 'change'}
                ],
                        IsFillIn3DD:[
                    { required: true,message: '必填项',trigger: 'change'}
                ],
                        IsTogetherView3DD:[
                    { required: true,message: '必填项',trigger: 'change'}
                ],
                        UnComplete3DDReason:[
                    { required: true,message: '必填项',trigger: 'change'}
                ],
                        IsComplete3DD:[
                    { required: true,message: '必填项',trigger: 'change'}
                ],
                        CompanionsOther:[
                    { required: true,message: '必填项',trigger: 'change'}
                ],
                        Companions:[
                    { required: true,message: '必填项',trigger: 'change'}
                ],
                        IsChatWithNurse:[
                    { required: true,message: '必填项',trigger: 'change'}
                ],
                        IsViewPriorData:[
                    { required: true,message: '必填项',trigger: 'change'}
                ],
                        VisitType:[
                    { required: true,message: '必填项',trigger: 'change'}
                ],
                        EndTime:[
                    { required: true,message: '必填项',trigger: 'change'}
                ],
                        StartTime:[
                    { required: true,message: '必填项',trigger: 'change'}
                ],
                        VistDate:[
                    { required: true,message: '必填项',trigger: 'change'}
                ],
	            OutpatientType:[
		            { required: true,message: '必填项',trigger: 'change'}
                ]
            },
            Companions:[],
            rowOff:false,
            dataRow:{},
            dialogForm1:false,
            formx:{
                NurtritionResourcesDetail:'',
                NurtritionResources:'',
                Advice3:'',
                Advice2:'',
                Advice1:'',
                DietQuestion3:'',
                DietQuestion2:'',
                DietQuestion1:'',
                TraceElementDetail:'',
                TraceElement:'',
                FoodCountDetail:'',
                FoodCount:'',
                EnergyDetail:'',
                Energy:'',
            },
            Plis:false,
            labelList:[],
            onOFFsub:false,
            sysId:'',
            ResearchObjectId:'',
            dialogForm2:false,
            tableDataQ:[],
            optionDiq:[],
	        hasCount:false
        }
    },
    filters:{
        IsFillInQuestionFilter(cellValue){
            if(cellValue==1){
                return '已完成'
            }
            else if(cellValue==0){
                return '未完成'
            }
            else{
                return '-'
            }
        },
        mobileFilter(cellValue) {
        	if(cellValue){
		        return cellValue.replace(/(\d{3})\d{4}(\d{4})/, "$1****$2");
            }

        },
        PeriodFilters(cellValue){
	        return filterPeriod(cellValue)
        },
    },
    created() {

    },
    computed:{
        ...mapGetters([
                'userIcon',
                'RoleGroup',
                'userId',
                'token',
	            'UserDic'
            ]),
    },
    async mounted(){
        let that=this;
        let now = new Date();
        let nowTime = now.getTime() ;
        let day = now.getDay();
        let oneDayLong = 24*60*60*1000 ;
        if(day==0){     //西方从周日算为第一天    2018/10/28
            day=7
        }
        let MondayTime = nowTime - (day-1)*oneDayLong  ;
        let SundayTime =  nowTime + (7-day)*oneDayLong ;
        let monday = dateForm(new Date(MondayTime));
        let sunday = dateForm(new Date(SundayTime));
        that.timeDate= [
            monday,
            sunday
        ];   //初始化时间范围
        JSON.parse(localStorage.getItem('nutClinic1'))?that.searchData=JSON.parse(localStorage.getItem('nutClinic1')):''
        that.getNurse()// 获取营养师
	    await that.GetCommunityDistrict()
	    that.searchData.districtNo=JSON.parse(that.UserDic).DistrictNo||that.searchData.districtNo||''
        that.getList()

    },
    beforeMount:function() {
        let that=this;
        let appHeight=$(window).height();
        let autoheight=(appHeight-288)+'px'
        that.maxHeight=autoheight
    },
    methods: {
        async GetCommunityDistrict(){    //获取社区行政区
            let that = this;
            await that.service({
                url: "/Dic/GetCommunityDistrict",
                method: "get",
                params: {
                }
            }).then(response => {
                that.optionDiq=response.dtData;
            })
            .catch(data => {

            });
        },
        deleteCrf(){         //删除crf
            let that=this;
            that.$confirm('确认要删除本条信息吗？', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            }).then(() => {
                that.service({
                    url:'/ResearchObject/DeleteNurtritionCaseReport',
                    method:'post',
                    data:{
                        ...that.FormAnli,
                    }
                }).then(response=>{
                    that.dialogFormAnli=false
                    that.getList()
                }).catch(data=>{
                    that.loadingQ=false
                })
            }).catch(() => {
                that.dialogFormAnli=false
                that.$message({
                    type: 'info',
                    message: '已取消'
                });
            });
        },
        changeFollowUpDate:function(row,val){
            this.setList(row)
        },
        changeLabellist:function(val){   //多选
            this.formx.NurtritionResources=val.join(',')
        },
        makeSurecopy:function(){  //确认复制
            let that=this;
            if(that.copyObject==null){
                that.$message({
                    message:'请选择一项行动计划',
                    type:'info'
                })
                return false
            }
            if(that.copyObject && that.copyObject.length>0){
                let val=that.copyObject
                that.formx={
                    NurtritionResourcesDetail:val[0].NurtritionResourcesDetail,
                    NurtritionResources:val[0].NurtritionResources,
                    Advice3:val[0].Advice3,
                    Advice2:val[0].Advice2,
                    Advice1:val[0].Advice1,
                    DietQuestion3:val[0].DietQuestion3,
                    DietQuestion2:val[0].DietQuestion2,
                    DietQuestion1:val[0].DietQuestion1,
                    TraceElementDetail:val[0].TraceElementDetail,
                    TraceElement:val[0].TraceElement,
                    FoodCountDetail:val[0].FoodCountDetail,
                    FoodCount:val[0].FoodCount,
                    EnergyDetail:val[0].EnergyDetail,
                    Energy:val[0].Energy,
                    ResearchObjectId:val[0].ResearchObjectId,
                    NutritionServiceId:val[0].NutritionServiceId,
                    IsDraft:''
                }
                that.formx.NutritionServiceId=that.tablerow.SYS_ID
                that.labelList=(val[0].NurtritionResources||'').split(',')
            }
            that.dialogForm2=false
        },
        singleChange:function(val){
            let that=this;
            that.copyObject=val
        },
        copyMove:function(){ //复制以往行动计划
            let that=this;
            that.getListQ()
            that.dialogForm2=true;
        },
        getListQ:function(){           //获取一级信息列表
            let that=this
            that.service({
                url:'/ResearchObject/GetMyNutritionPrescription',
                method:'get',
                params:{
                    researchObjectId:that.tablerow.ResearchObjectId,
                }
            }).then(response=>{
                that.loadingQ=false
                that.tableDataQ=response.dtData;
                that.totalQ=parseInt(response.dtData[0].TotalCount)
            }).catch(data=>{
                that.loadingQ=false
            })
        },
        submitForm:function(type){   //提交
            let that=this;
            if(that.onOFFsub){
                that.subDisabled=true
                return false;
            }
            that.onOFFsub=true
            if((this.formx.Energy==''||this.formx.EnergyDetail==''||this.formx.FoodCount==''||this.formx.FoodCountDetail==''||this.formx.TraceElement==''||this.formx.TraceElementDetail==''||this.formx.DietQuestion1==''||this.formx.Advice1==''||this.formx.NurtritionResources==''||this.formx.NurtritionResourcesDetail=='')&&(type==1)){
                that.$message({
                    message: '不是可选的选项，均为必填项',
                    type: 'warning'
                });
                that.onOFFsub=false;
                return false;
            }
            setTimeout(()=>{
                that.service({
                    url:'/ResearchObject/SaveNutritionPrescription',
                    method:'post',
                    data:{
                        ...that.formx,
                        IsDraft:type,
                        Creater:that.userIcon,
                        CreaterId:that.token,
                }}).then(response=>{
                    that.dialogForm1=false
                    that.getList()
                }).catch(data=>{
                    that.onOFFsub=false;
                    that.subDisabled=false
                })
            },200)
        },
        changeCops:function(val){
            this.FormAnli.Companions=val.join(',')
        },
        reportSure:function(formName){    //确认
            let that=this;
            if(that.rowOff){
                return false
            }
            that.rowOff=true
            that.$refs[formName].validate((valid) =>{
                if (valid) {
                	if(parseFloat(that.FormAnli.EndTime.replace(':','')) <=
		                parseFloat(that.FormAnli.StartTime.replace(':','')) ){
		                that.$notify({
			                title: '提示',
			                message: '结束时间应晚于开始时间！',
			                type: 'error'
		                });
		                that.rowOff=false
		                return false
                    }
                   that.service({
                    url: "/ResearchObject/SaveNurtritionCaseReport",
                    method: "post",
                    data: {
                        ...that.FormAnli,
                    }
                }).then(response => {
                    that.dialogFormAnli=false
                    that.$message({
                        message:'保存成功',
                        type:'success'
                    })
                    that.$confirm('自动将事项状态改为“已完成”，确定吗？', '提示', {
                        confirmButtonText: '确定',
                        cancelButtonText: '取消',
                        type: 'warning'
                    }).then(() => {
                        that.dataRow.CompleteState='1';
                        that.rowOff=false
                        that.setList(that.dataRow)
                    }).catch(() => {
                        that.$message({
                            type: 'info',
                            message: '已取消'
                        });
                        that.getList()
                        that.rowOff=false
                    });

                    }).catch(data => {});
                    that.dialogFormAnli=false
                }
                else {
                        that.rowOff=false
                        return false
                    }
                })
        },
        handleReport:function(row){    //案例报告表
            let that=this;
	        row.NurtritionCaseReportId!==''?that.hasCount=true:that.hasCount=false
            that.dialogFormAnli=true;
            that.Companions=[]
            that.rowOff=false
            that.dataRow=''
            that.formPoint={};
            that.FormAnli={
                IsCommunicationWithNurse:'',
                IsSetNextVisitDate:'',
                IsCompleteNurtitionPrescription:'',
                IsTogetherConfirmDietReport:'',
                IsSaveDietReport:'',
                IsFillInDiet:'',
                IsReviewDiet:'',
                IsFillIn3DD:'',
                IsTogetherView3DD:'',
                UnComplete3DDReason:'',
                IsComplete3DD:'',
                CompanionsOther:'',
                Companions:'',
                IsChatWithNurse:'',
                IsViewPriorData:'',
                VisitType:'',
                EndTime:'',
                StartTime:row.VisitTime||'',
                VistDate:row.VisitDate||'',
                OtherOpinion:'',
	            OutpatientType:''
            }
            that.formPoint=row
            that.dataRow=row;
            that.$nextTick(function () {
                that.$refs['FormAnli'].resetFields();
            })
            that.FormAnli.ResearchObjectId=row.ResearchObjectId
            that.FormAnli.NutritionServiceId=row.SYS_ID
            that.service({
                url: "/ResearchObject/GetNurtritionCaseReport",
                method: "get",
                params: {
                    nutritionServiceId:row.SYS_ID
                }
            }).then(response => {
                if(response.dtData.length>0){
                    that.FormAnli=response.dtData[0]
                    that.Companions=(response.dtData[0].Companions||'').split(',')
                }
            }).catch(data => {

            });
        },
        handleTable:function(row){  //营养处方
            let that=this;
            that.dialogForm1=true;
            that.onOFFsub=false;
	        that.formPoint={}
            that.tablerow=row
            that.labelList=[]
            that.formx={
                IsDraft:'',
                NurtritionResourcesDetail:'',
                NurtritionResources:'',
                Advice3:'',
                Advice2:'',
                Advice1:'',
                DietQuestion3:'',
                DietQuestion2:'',
                DietQuestion1:'',
                TraceElementDetail:'',
                TraceElement:'',
                FoodCountDetail:'',
                FoodCount:'',
                EnergyDetail:'',
                Energy:'',
            }
	        that.formPoint=row
            that.formx.ResearchObjectId=row.ResearchObjectId
            that.formx.NutritionServiceId=row.SYS_ID
        },
        tableSure:function(){    //确认
            let that=this;
            that.setList(that.addForm1)
            that.dialogVisible=false
        },
        checkList:function(){   //查询
            this.pageId=1;
            this.pageSize=10;
            this.total=null;
            this.getList()
            let storageObj=this.searchData
            localStorage.setItem('nutClinic1',JSON.stringify(storageObj))
        },
        changeFollowUpDateOne:function(row,val){
            let that=this;
            if(row.AppointState==0){
                this.$confirm('是否将预约状态改为已确认 , 是否继续?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {
                   row.AppointState='1';
                   that.setList(row)
                }).catch(() => {
                    that.setList(row)
                });
            }
            else{
                 that.setList(row)
            }
        },
        jumpQuestion:function(row){   //问卷跳转
            let that=this;
            if(row.IsFillInQuestionnaire==undefined){
                return false
            }
            that.$router.push({
                path:'/participant/editor',
                query:{
                    id:row.ResearchObjectId,
                    mobile:row.Mobile,
                    researchNo:row.ResearchNo,
                    isOther:1
                }
            })
        },
        jumpMove:function(row){  //跳转行动计划
            let that=this;
            that.$router.push({
                path:'/participant/editor',
                query:{
                    id:row.ResearchObjectId,
                    mobile:row.Mobile,
                    researchNo:row.ResearchNo,
                    isOther:3
                }
            })
        },
        JumpUserinfo:function(row){   //跳转用户基本信息
            let that=this;
            that.$router.push({
                path:'/participant/editor',
                query:{
                    id:row.ResearchObjectId,
                    mobile:row.Mobile,
                    researchNo:row.ResearchNo,
                }
            })
        },
        handleSizeChange(val) {       //条数改变
            this.pageSize=val;
            this.getList()
        },
        handleCurrentChange(val) {    //页数改变
            this.pageId = val
            this.getList()
        },
        handleSizeChangeQ(val) {       //条数改变
            this.pageSizeQ=val;
            this.getListQ()
        },
        handleCurrentChangeQ(val) {    //页数改变
            this.pageIdQ = val
            this.getListQ()
        },
        setList:function(row){  //修改
            let that=this;
            row.CancleReason = row.CompleteState != 2 ? '' : row.CancleReason
            that.service({
                url:'/ResearchObject/SaveNutritionService',
                method:'post',
                data:{
                        ...row
                }
                }).then(response=>{
                        that.$message({
                        message: '修改成功',
                        type: 'success'
                    });
                    that.getList()
                }).catch(data=>{
                    that.getList()
            })
        },
        getList:function(){           //获取一级信息列表
            let that=this
            that.loading=true
            that.service({
                url:'/ResearchObject/GetNutritionService',
                method:'get',
                params:{
                    pageCount:(that.pageId-1),
                    pageSize:that.pageSize,
                        ...that.searchData,
                    startDate:that.timeDate?that.timeDate[0]:'',
                    endDate:that.timeDate?that.timeDate[1]:'',
                }
                }).then(response=>{
                    that.tableData=response.dtData;
                    that.total =parseInt(response.dtData[0].TotalCount);
                    that.loading=false
                }).catch(data=>{
                that.loading=false
            })
        },
        getNurse:function(){
            let that=this;
            that.service({
                url:'/Sys/GetNurse',
                method:'get',
                params:{
                    roleGroup:'5'
                }
            }).then(response=>{
                let options=response.dtData
                for(let i of options){    //处理姓名账号不一致，Nan
                    i.Name=i.Name || ''
                    let username=i.Surname+i.Name
                    username=='undefined'?username=i.UserCode:username=username
                    i.icons=username
                }
                that.optionsNurse=options;
            }).catch(data=>{

            })
        },
        changeNurse:function(row,val){
            let that=this;
            this.$confirm('更换营养师后，请重新填写就诊时间, 是否继续?', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            }).then(() => {
                that.optionsNurse.forEach(function (item) { //绑定ID
                    if(item.icons==val){
                        row.NurseId=item.SYS_ID
                    }
                })
                row.VisitTime=''
                this.setList(row)
            }).catch(() => {
                that.$message({
                    message:'已取消',
                    type:'info'
                })
                that.getList()
            });
        }
    }
  }
function addZero(s){
    return s < 10 ? '0' + s: s;
}
function dateForm(data){
    return   new Date(data).getFullYear()+'-'+addZero((new Date(data).getMonth()+1))+'-'+addZero(new Date(data).getDate())
}
</script>
<style scoped lang="scss">
    .formX{
    .top{
        text-align: center;
    }
    ul{
    li{
        margin:20px;
    h3{
        color: #606266;
        font-weight: normal;
        font-size: 17px;
    }
    h5{
        font-weight: normal;
        margin:5px 0;
    }
    p{
        color: #999999;
        margin-bottom: 10px;
        margin:10px 0px;
    }
    }
    }
    }
    .click_line{cursor: pointer;color:#409EFF;}
    .fade-enter-active, .fade-leave-active {
        transition: opacity .4s;
    }
    .fade-enter, .fade-leave-to{
        opacity: 0;
    }
    .pagination-fixed{
     position: static;
    }
    .formPlebek{color:#0066FF }
    .conItem .el-form-item__content{height: auto}
</style>
